import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Stack;

public class demo2 {
    public static boolean chkParenthesis(String A, int n) {
        // write code here
        if(n==0) {
            return false;
        }
        Stack<Character> queue = new Stack<>();
        for(int i=0;i<n;i++) {
            char s = A.charAt(i);
            if(s=='('||s=='{'||s=='[') {
                queue.add(s);
            } else if(((s==')'||s=='}'||s==']') && !(queue.isEmpty()))) {
                char t = queue.peek();
                if(!((t=='('&&s==')')||(t=='{'&&s=='}')||(t=='['&&s==']'))) {
                    return false;
                }
                queue.pop();
            } else {
                return false;
            }
        }
        if(queue.isEmpty()) {
            return true;
        }
        return false;
    }
    public static void main(String[] args) {
        System.out.println(chkParenthesis("())()()(((d",11));
    }
}
